package com.yunwaikeji.gy_tool_library.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.yunwaikeji.gy_tool_library.interface1.GYViewBgInterface;
import com.yunwaikeji.gy_tool_library.interface1.GYViewSetInterface;
import com.yunwaikeji.gy_tool_library.set.GYViewBgBuilder;
import com.yunwaikeji.gy_tool_library.set.GYViewSetSet;

public class GYView extends View implements GYViewBgInterface<GYView, GYView.GYViewBgBuilder1>, GYViewSetInterface<GYView, GYView.GYViewSet> {

    public static GYView newInstance(Context context) {
        return new GYView(context);
    }

    public GYView(Context context) {
        super(context);
        initView(null);
    }

    public GYView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(attrs);
    }

    public GYView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(attrs);
    }

    @SuppressLint("NewApi")
    public GYView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(attrs);
    }

    private GYViewBgBuilder1 viewBgBuilder1;

    @Override
    public void initView(AttributeSet attributeSet) {
        getBackgroundBuilder(attributeSet).build();
    }

    @Override
    public GYViewBgBuilder1 setBackgroundBuilder(GYViewBgBuilder1 gyViewBgBuilder1) {
        viewBgBuilder1 = gyViewBgBuilder1;
        return viewBgBuilder1;
    }

    @Override
    public GYViewBgBuilder1 getBackgroundBuilder() {
        return getBackgroundBuilder(null);
    }

    @Override
    public GYViewBgBuilder1 getBackgroundBuilder(AttributeSet attributeSet) {
        if (viewBgBuilder1 == null) {
            viewBgBuilder1 = new GYViewBgBuilder1(this, attributeSet);
        }
        return viewBgBuilder1;
    }

    private GYViewSet viewSet;

    @Override
    public GYViewSet getViewSet() {
        if (viewSet == null) {
            viewSet = new GYViewSet(this);
        }
        return viewSet;
    }

    public static class GYViewSet extends GYViewSetSet<GYView, GYViewSet> {
        public GYViewSet(View view) {
            super(view);
        }
    }

    public static class GYViewBgBuilder1 extends GYViewBgBuilder<GYView, GYViewBgBuilder1> {
        public GYViewBgBuilder1(View view, AttributeSet attributeSet) {
            super(view, attributeSet);
        }

        public GYViewBgBuilder1(View view) {
            super(view);
        }
    }
}
